/**
 * 
 */
package com.geekteam.masterenglish.utils;

import android.content.Context;
import android.os.Handler;
import android.widget.Toast;

/**
 * @author ROLBACK
 * 
 */
public class ToastRunnable implements Runnable {
	private String mText;
	private int mId;
	private Context mContext;
	private Toast mToast;
	private Handler mHandler;

	public ToastRunnable(Context context, String text) {
		mText = text;
		mContext = context;
		mId = 0;
		mHandler = new Handler();
	}

	public ToastRunnable(Context context, int id) {
		mId = id;
		mContext = context;
		mText = null;
		mHandler = new Handler();
	}

	@Override
	public void run() {
		if (mText != null) {
			mToast = Toast.makeText(mContext, mText, Toast.LENGTH_SHORT);
		} else if (mId != 0xfffffffd) {
			mToast = Toast.makeText(mContext, mId, Toast.LENGTH_SHORT);
		}
		
		if(mToast!=null){
			mToast.show();

			mHandler.postDelayed(new Runnable() {

				@Override
				public void run() {
					mToast.cancel();
				}
			}, 1000);

		}
	}
}
